<script setup lang="ts" name="Datasource">
import useStore from "@/store";
import { reactive, getCurrentInstance, ComponentInternalInstance, toRaw, onMounted } from "vue";
import { table } from "./index";
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
// eslint-disable-next-line new-cap
const obj = reactive(new table());
const state = toRaw(obj).baseData;
onMounted(() => {
  obj.getDomHeight(proxy);
});
</script>
<template>
  <div class="box shadow">
    <div ref="boxHeader" class="box_header">
      <div class="box_header_title">我的工作</div>
      <div></div>
    </div>
    <el-image src="@/assets/icons/"></el-image>
    <div ref="boxContent" class="box_content">
      <el-form ref="queryRef" label-position="right" :model="state.queryParams" :inline="true" label-width="auto">
        <el-form-item label="数据库名称" prop="name">
          <el-input v-model="state.queryParams.name" placeholder="请输入数据库名称" clearable />
        </el-form-item>
        <el-form-item label="主机 ip" prop="host">
          <el-input v-model="state.queryParams.host" placeholder="请输入主机 ip" clearable />
        </el-form-item>
        <el-form-item label="数据库端口号" prop="port">
          <el-input v-model="state.queryParams.port" placeholder="请输入数据库端口号" clearable />
        </el-form-item>
        <el-form-item label="用户名" prop="username">
          <el-input v-model="state.queryParams.username" placeholder="请输入用户名" clearable />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="state.queryParams.password" placeholder="请输入密码" clearable />
        </el-form-item>
        <el-form-item label="状态" prop="isStatus">
          <el-input v-model="state.queryParams.isStatus" placeholder="输入状态" clearable />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="state.queryParams.password" placeholder="请输入密码" clearable />
        </el-form-item>
        <el-form-item label="状态" prop="isStatus">
          <el-input v-model="state.queryParams.isStatus" placeholder="输入状态" clearable />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="state.queryParams.password" placeholder="请输入密码" clearable />
        </el-form-item>
        <el-form-item label="状态" prop="isStatus">
          <el-input v-model="state.queryParams.isStatus" placeholder="输入状态" clearable />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="state.queryParams.password" placeholder="请输入密码" clearable />
        </el-form-item>
        <el-form-item label="状态" prop="isStatus">
          <el-input v-model="state.queryParams.isStatus" placeholder="输入状态" clearable />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="state.queryParams.password" placeholder="请输入密码" clearable />
        </el-form-item>
        <el-form-item label="状态" prop="isStatus">
          <el-input v-model="state.queryParams.isStatus" placeholder="输入状态" clearable />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="state.queryParams.password" placeholder="请输入密码" clearable />
        </el-form-item>
        <el-form-item label="状态" prop="isStatus">
          <el-input v-model="state.queryParams.isStatus" placeholder="输入状态" clearable />
        </el-form-item>
      </el-form>
      <div class="box_content_button">
        <el-button>
          <span>展开&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
          <el-icon><ArrowDownBold /></el-icon>
        </el-button>
        <div>
          <el-button type="primary" @click="obj.handleQuery">查询</el-button>
          <el-button type="" @click="obj.handleQuery">自定义查询</el-button>
          <el-button type="" @click="obj.resetQuery(proxy)">重置</el-button>
        </div>
      </div>
      <div class="box_content_table-button">
        <el-button class="icon-button" type="primary" @click="obj.handleAdd()">新增</el-button>
        <el-button class="icon-button color">周期调整</el-button>
        <el-button class="icon-button" @click="obj.handleExport(proxy)">导出</el-button>
      </div>
    </div>
    <div class="box_table">
      <el-table
        :data="state.datasourceList"
        stripe
        :height="state.domHeight"
        style="width: 100%"
        on-change="state.handleSelectionChange"
        border
      >
        <el-table-column type="selection" align="center" width="55" />
        <el-table-column label="数据库名称" align="center" prop="name" />
        <el-table-column label="主机 ip" align="center" prop="host" />
        <el-table-column label="数据库端口号" align="center" prop="port" />
        <el-table-column label="用户名" align="center" prop="username" />
        <el-table-column label="密码" align="center" prop="password" />
        <el-table-column label="状态" align="center" prop="isStatus" />
        <el-table-column label="是否连接成功" align="center" prop="isConnect" />
        <el-table-column label="操作" align="center" width="180">
          <template #default="scope">
            <el-button class="table-button" type="primary" icon="Edit" @click="obj.handleUpdate(scope.row)">修改 </el-button>
            <el-button class="table-button" type="warning" icon="Delete" @click="obj.handleDelete(scope.row)">删除 </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div ref="boxPagination" class="box_pagination">
      <el-pagination
        v-model:currentPage="state.queryParams.pageNum"
        v-model:page-size="state.queryParams.pageSize"
        :page-sizes="[10, 20, 30, 40]"
        :small="state.small"
        :background="state.background"
        layout="total, sizes, prev, pager, next, jumper"
        :total="state.total"
        @pagination="obj.getList"
        @size-change="obj.handleSizeChange"
        @current-change="obj.handleCurrentChange"
      />
    </div>
  </div>
  <!-- 添加或修改数据源 数据源对话框 -->
  <el-dialog v-model="state.open" :title="state.title" width="500px" append-to-body>
    <el-form ref="dataFormRef" :model="state.form" :rules="state.rules" label-width="120px">
      <el-form-item label="数据库名称" prop="name">
        <el-input v-model="state.form.name" placeholder="请输入数据库名称" />
      </el-form-item>
      <el-form-item label="主机 ip" prop="host">
        <el-input v-model="state.form.host" placeholder="请输入主机 ip" />
      </el-form-item>
      <el-form-item label="数据库端口号" prop="port">
        <el-input v-model="state.form.port" placeholder="请输入数据库端口号" />
      </el-form-item>
      <el-form-item label="用户名" prop="username">
        <el-input v-model="state.form.username" placeholder="请输入用户名" />
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="state.form.password" placeholder="请输入密码" />
      </el-form-item>
      <el-form-item label="状态">
        <el-input v-model="state.form.isStatus" placeholder="请输入状态"> </el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="obj.submitForm(proxy)">确 定</el-button>
        <el-button @click="obj.cancel()">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<style lang="scss" scoped>
.box {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding: 0 20px 20px;
  overflow: auto;
  &_header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    height: 68px;
    margin-bottom: 20px;
    font-size: 22px;
    font-weight: 700;
    color: $font-two-color;
    background-color: $font-four-color;
    border-bottom: 1px solid $background-color;
  }
  &_content {
    ::v-deep(.dclm-form) {
      display: flex;
      flex-wrap: wrap;
      .dclm-form-item {
        margin-right: 10px;
        .dclm-input__inner {
          width: 259px;
        }
      }
    }
    &_button {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 12px;
      &:deep(.dclm-button) {
        width: 104px;
        height: 32px;
      }
    }
    &_table-button {
      display: flex;
      margin-bottom: 10px;
      .color {
        background-color: $theme-two-color;
      }
      .color1 {
        background-color: $theme-two-color;

        // color: $font-four-color;
        &:deep(.dclm-icon) {
          // color: $font-four-color;
        }
      }
    }
  }
  &_table {
    &:deep(.dclm-pagination__editor) {
      min-width: 49px;
      height: 27px;
    }
  }
  &_pagination {
    display: flex;
    justify-content: flex-end;
    width: 100%;
    background-color: $font-four-color;
  }
}
</style>
